package com.demo.study.thread;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

/**
 * contains方法用于判断list集合是否包含某个元素
 * <p>
 * containsKey方法用于判断Map键中是否包含某个键
 * <p>
 * containsValue方法用于判断map中是否包含某个value值
 *
 * @Author Hateyes
 * @Date 2020-07-25 10:25
 */

public class ContainsDemo {
    public static void main(String[] args) {
        List list = new ArrayList();

        list.add("A");

        list.add("B");

        list.add("C");

        list.add("D");


        Map map = new HashMap();

        map.put("1", "11");

        map.put("B", "22");

        map.put("3", "33");

        map.put("4", "44");

        long start = System.currentTimeMillis();
        System.out.println(list.contains("B"));
        long end = System.currentTimeMillis();
        System.out.println("获取list的"+(end-start)+ "s");
        //获取list的10287s
        long start1 = System.currentTimeMillis();
        System.out.println(map.containsKey("B")); //判断map中是否有"1"这个键
        long end1 = System.currentTimeMillis();
        System.out.println("获取map的"+(end1-start1));
        //获取map的1488
    }

}
